package com.example.apidocserver.infrastructure.config.security;

import com.example.apidocserver.domain.user.entity.UsrUsers;
import com.example.apidocserver.infrastructure.constants.SystemConstants;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 登录框架用户对象
 *
 * @author xyqlg
 */
public class UserDetailsImpl extends UsrUsers implements UserDetails {
    private List<Integer> dataRoleValList;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> authorities = new ArrayList<>();
        authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
        authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
        return authorities;
    }

    @Override
    public String getPassword() {
        return getCredential();
    }

    @Override
    public String getUsername() {
        return getIdentifier();
    }

    @Override
    public boolean isAccountNonExpired() {
        return SystemConstants.NO.equals(getExpired());
    }

    @Override
    public boolean isAccountNonLocked() {
        return SystemConstants.NO.equals(getLocked());
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return SystemConstants.YES.equals(getEnabled());
    }

    public List<Integer> getDataRoleValList() {
        return dataRoleValList;
    }

    public void setDataRoleValList(List<Integer> dataRoleValList) {
        this.dataRoleValList = dataRoleValList;
    }
}
